package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.product.mapper.BaseCategory1Mapper;
import com.atguigu.gmall.product.mapper.BaseCategory2Mapper;
import com.atguigu.gmall.product.mapper.BaseCategory3Mapper;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@SuppressWarnings("all")
public class BaseCategoryServiceImpl implements BaseCategoryService {


    @Autowired
    private BaseCategory1Mapper baseCategory1Mapper;

    @Autowired
    private BaseCategory2Mapper baseCategory2Mapper;


    @Autowired
    private BaseCategory3Mapper baseCategory3Mapper;


    @Override
    public List<BaseCategory1> getCategory1() {
        QueryWrapper<BaseCategory1> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "name");
        List<BaseCategory1> category1List = baseCategory1Mapper.selectList(queryWrapper);
        return category1List;
    }


    @Override
    public List<BaseCategory2> getCategory2(Long category1Id) {
        //1.创建条件对象
        LambdaQueryWrapper<BaseCategory2> queryWrapper = new LambdaQueryWrapper<>();
        //1.1 设置查询条件
        queryWrapper.eq(BaseCategory2::getCategory1Id, category1Id);
        //1.2 设置查询字段
        queryWrapper.select(BaseCategory2::getId, BaseCategory2::getName);

        //2.执行列表查询
        List<BaseCategory2> category2List = baseCategory2Mapper.selectList(queryWrapper);
        return category2List;
    }


    @Override
    public List<BaseCategory3> getCategory3(Long category2Id) {
        LambdaQueryWrapper<BaseCategory3> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BaseCategory3::getCategory2Id, category2Id);
        queryWrapper.select(BaseCategory3::getId, BaseCategory3::getName);
        return baseCategory3Mapper.selectList(queryWrapper);
    }

    @Override
    public List<BaseCategory2> getCategory2() {
        return null;
    }
}
